package cn.hist.hfp.converter;

import cn.hist.hfp.entity.PetOrder;
import cn.hist.hfp.vo.PetOrderVO;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Component
public class PetOrderConverter {

    private SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public PetOrderVO convert(PetOrder order) {
        return PetOrderVO.builder()
                .id(order.getId())
                .adoptionDate(formatter.format(order.getAdoptionDate()))
                .birthDate(formatter.format(order.getPet().getBirthDate()))
                .description(order.getPet().getDescription())
                .petImage(order.getPet().getImage())
                .petName(order.getPet().getName())
                .speciesName(order.getPet().getSpecies().getName())
                .speciesDescription(order.getPet().getSpecies().getDescription())
                .build();
    }

    public List<PetOrderVO> convert(List<PetOrder> PetOrders) {
        List<PetOrderVO> PetOrderVOS = new ArrayList<>();
        for (PetOrder PetOrder: PetOrders) {
            PetOrderVOS.add(convert(PetOrder));
        }
        return PetOrderVOS;
    }

    public Set<PetOrderVO> convert(Set<PetOrder> PetOrders) {
        Set<PetOrderVO> PetOrderVOS = new HashSet<>();
        for (PetOrder PetOrder: PetOrders) {
            PetOrderVOS.add(convert(PetOrder));
        }
        return PetOrderVOS;
    }
}
